<template>
  <el-drawer v-model="drawerVisible" title="搜索" direction="rtl" size="350px">
    <template #header>
      <span class="text-16px font-700">搜索</span>
    </template>
    <div class="search-drawer" style="height: 100%">
      <el-form
        ref="queryFormRef"
        :inline="true"
        :model="queryParams"
        class="-mb-15px"
        label-width="68px"
      >
        <el-form-item label="承运商统一信用代码" prop="carrierUcss">
          <el-input
            v-model="queryParams.carrierUcss"
            placeholder="请输入承运商统一信用代码"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="承运商/车队长名称" prop="carrierName">
          <el-input
            v-model="queryParams.carrierName"
            placeholder="请输入承运商/车队长名称"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="司机名称" prop="driverName">
          <el-input
            v-model="queryParams.driverName"
            placeholder="请输入司机名称"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="司机身份证号" prop="driverIdCardNo">
          <el-input
            v-model="queryParams.driverIdCardNo"
            placeholder="请输入司机身份证号"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="司机性别" prop="driverGender">
          <el-input
            v-model="queryParams.driverGender"
            placeholder="请输入司机性别"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="司机手机号" prop="driverPhone">
          <el-input
            v-model="queryParams.driverPhone"
            placeholder="请输入司机手机号"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="司机类别" prop="driverKind">
          <el-input
            v-model="queryParams.driverKind"
            placeholder="请输入司机类别"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="签发机关" prop="grantOrg">
          <el-input
            v-model="queryParams.grantOrg"
            placeholder="请输入签发机关"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="身份证有效起始日期" prop="icStartDate">
          <el-date-picker
            v-model="queryParams.icStartDate"
            value-format="YYYY-MM-DD HH:mm:ss"
            type="daterange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
            class="!w-220px"
          />
        </el-form-item>
        <el-form-item label="身份证有效截止日期" prop="icEndDate">
          <el-date-picker
            v-model="queryParams.icEndDate"
            value-format="YYYY-MM-DD HH:mm:ss"
            type="daterange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
            class="!w-220px"
          />
        </el-form-item>
        <el-form-item label="身份证正面" prop="idCardFurl">
          <el-input
            v-model="queryParams.idCardFurl"
            placeholder="请输入身份证正面"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="身份证反面" prop="idCardBurl">
          <el-input
            v-model="queryParams.idCardBurl"
            placeholder="请输入身份证反面"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="驾驶证号" prop="driverLicenseNo">
          <el-input
            v-model="queryParams.driverLicenseNo"
            placeholder="请输入驾驶证号"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="准驾类型" prop="approveType">
          <el-select
            v-model="queryParams.approveType"
            placeholder="请选择准驾类型"
            clearable
            class="!w-240px"
          >
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="初次领证时间" prop="firstCertDate">
          <el-date-picker
            v-model="queryParams.firstCertDate"
            value-format="YYYY-MM-DD HH:mm:ss"
            type="daterange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
            class="!w-220px"
          />
        </el-form-item>
        <el-form-item label="发证机关" prop="issueOrg">
          <el-input
            v-model="queryParams.issueOrg"
            placeholder="请输入发证机关"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="驾驶证有效起始日期" prop="dlStartDate">
          <el-date-picker
            v-model="queryParams.dlStartDate"
            value-format="YYYY-MM-DD HH:mm:ss"
            type="daterange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
            class="!w-220px"
          />
        </el-form-item>
        <el-form-item label="驾驶证有效终止日期" prop="dlEndDate">
          <el-date-picker
            v-model="queryParams.dlEndDate"
            value-format="YYYY-MM-DD HH:mm:ss"
            type="daterange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
            class="!w-220px"
          />
        </el-form-item>
        <el-form-item label="驾驶证正面" prop="licenseFurl">
          <el-input
            v-model="queryParams.licenseFurl"
            placeholder="请输入驾驶证正面"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="驾驶证反面" prop="licenseBurl">
          <el-input
            v-model="queryParams.licenseBurl"
            placeholder="请输入驾驶证反面"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="从业资格证号" prop="certNo">
          <el-input
            v-model="queryParams.certNo"
            placeholder="请输入从业资格证号"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="从业资格证类别" prop="certKind">
          <el-input
            v-model="queryParams.certKind"
            placeholder="请输入从业资格证类别"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="发证机关" prop="certIssueOrg">
          <el-input
            v-model="queryParams.certIssueOrg"
            placeholder="请输入发证机关"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="有效期至" prop="certEndDate">
          <el-date-picker
            v-model="queryParams.certEndDate"
            value-format="YYYY-MM-DD HH:mm:ss"
            type="daterange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
            class="!w-220px"
          />
        </el-form-item>
        <el-form-item label="从业资格证照" prop="certUrl">
          <el-input
            v-model="queryParams.certUrl"
            placeholder="请输入从业资格证照"
            clearable
            class="!w-240px"
          />
        </el-form-item>
        <el-form-item label="审核状态 0-待审核 1-审核通过 -1审核失败" prop="authStatus">
          <el-select
            v-model="queryParams.authStatus"
            placeholder="请选择审核状态 0-待审核 1-审核通过 -1审核失败"
            clearable
            class="!w-240px"
          >
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="创建时间" prop="createTime">
          <el-date-picker
            v-model="queryParams.createTime"
            value-format="YYYY-MM-DD HH:mm:ss"
            type="daterange"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]"
            class="!w-220px"
          />
        </el-form-item>
        <el-form-item label="机构ID" prop="deptId">
          <el-input
            v-model="queryParams.deptId"
            placeholder="请输入机构ID"
            clearable
            class="!w-240px"
          />
        </el-form-item>
      </el-form>
    </div>
    <template #footer>
      <div style="flex: auto">
        <el-button @click="reset">重置</el-button>
        <el-button type="primary" @click="search">搜索</el-button>
      </div>
    </template>
  </el-drawer>
</template>

<script setup lang="ts">
  import { computed, ref } from 'vue'

  // 定义 props 和 emits
  const props = defineProps({
    modelValue: {
      type: Object,
      required: true,
    }
  });

  const emit = defineEmits(['update:modelValue', 'search', 'reset']);

  // 控制抽屉显示
  const drawerVisible = ref(false);

  // 使用 computed 实现双向绑定
  const queryParams = computed({
    get: () => props.modelValue,
    set: (value) => emit('update:modelValue', value)
  });

  // 打开抽屉
  function open() {
    drawerVisible.value = true;
  }

  // 关闭抽屉
  function close() {
    drawerVisible.value = false;
  }

  // 搜索
  function search() {
    close();
    emit('search', queryParams.value);
  }

  const queryFormRef = ref()
  // 重置
  function reset() {
    queryFormRef.value.resetFields()
    emit('reset', queryParams.value);
  }

  // 暴露 open 方法
  defineExpose({
    open
  });
</script>

<style lang="scss" scoped>
  .search-drawer {
    ::v-deep {
      .el-form {
        height: 98%;
      }
    }
  }
</style>
